<!---
Copyright: (c) 2006 The MachBlog Authors
Authors: Matt Woodward (mpwoodward@gmail.com) & Peter J. Farrell (pjf@maestropublishing.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.

$Id: TrackbackService.cfc 834 2006-07-03 19:55:10Z mpwoodward $

Notes:
--->
<cfcomponent
	displayname="TrackbackService"
	output="false"
	hint="TrackbackService for MachBlog.">

	<!---
	PROPERTIES
	--->
	<cfproperty name="trackbackGateway" type="org.machblog.trackback.TrackbackGateway" required="true" />
	<cfproperty name="trackbackDAO" type="org.machblog.trackback.TrackbackDAO" required="true" />
	<cfproperty name="userFacade" type="org.machblog.facades.UserFacade" required="true" />

	<!---
	INITIALIZATION / CONFIGURATION
	--->
	<cffunction name="init" access="public" output="false" returntype="TrackbackService" 
			hint="Constructor for this CFC">
		<cfreturn this />
	</cffunction>

	<cffunction name="setTrackbackGateway" access="public" output="false" returntype="void"
		hint="Dependency: injected">
		<cfargument name="trackbackGateway" type="TrackbackGateway" required="true" />
		<cfset variables.trackbackGateway = arguments.trackbackGateway />
	</cffunction>	
	<cffunction name="getTrackbackGateway" access="public" output="false" returntype="TrackbackGateway">
		<cfreturn variables.trackbackGateway />
	</cffunction>
	
	<cffunction name="setTrackbackDAO" access="public" output="false" returntype="void"
		hint="Dependency: injected">
		<cfargument name="trackbackDAO" type="TrackbackDAO" required="true" />
		<cfset variables.trackbackDAO = arguments.trackbackDAO />
	</cffunction>	
	<cffunction name="getTrackbackDAO" access="public" output="false" returntype="TrackbackDAO">
		<cfreturn variables.trackbackDAO />
	</cffunction>
	
	<cffunction name="setUserFacade" access="public" output="false" returntype="void"
		hint="Dependency: injected">
		<cfargument name="userFacade" type="org.machblog.facades.UserFacade" 
				required="true" />
		<cfset variables.userFacade = arguments.userFacade />
	</cffunction>
	<cffunction name="getUserFacade" access="public" output="false" 
			returntype="org.machblog.facades.UserFacade">
		<cfreturn variables.userFacade />
	</cffunction>
	
	<cffunction name="getTrackbackBean" access="public" output="false" returntype="Trackback">
		<cfreturn createObject("component", "Trackback").init() />
	</cffunction>
	
	<!---
	PUBLIC FUNCTIONS - GATEWAY RELATED
	--->
	<cffunction name="getTrackbacks" access="public" output="false" returntype="query" 
		hint="Returns a query containing trackbacks for an entry">
		<cfargument name="entryId" type="uuid" required="true" />
		<cfargument name="getAll" type="boolean" required="false" default="false" />
		<cfreturn getTrackbackGateway().getTrackbacks(arguments.entryId, arguments.getAll) />
	</cffunction>
	
	<cffunction name="getRecentTrackbacks" access="public" output="false" returntype="query" 
		hint="Returns a query containing recent trackbacks across all entries">
		<cfargument name="numToGet" type="numeric" required="true" />
		<cfargument name="includeInactive" type="boolean" required="true" />
		<cfreturn getTrackbackGateway().getRecentTrackbacks(arguments.numToGet, arguments.includeInactive) />
	</cffunction>
	
	<cffunction name="getTrackbackCountByDate" access="public" output="false" returntype="numeric" 
		hint="Returns the number of trackbacks added on a particular date">
		<cfargument name="trackbackDate" type="date" required="false" default="#Now()#" />
		<cfreturn getTrackbackGateway().getTrackbackCountByDate(arguments.trackbackDate) />
	</cffunction>
	
	<cffunction name="deactivateTrackbacksByEntryId" access="public" output="false" returntype="void" 
			hint="Deactivates trackbacks for an entry">
		<cfargument name="entryId" type="uuid" required="true" />
		<cfset getTrackbackGateway().deactivateTrackbacksByEntryId(arguments.entryId) />
	</cffunction>
	
	<cffunction name="activateTrackbacksByEntryId" access="public" output="false" returntype="void" 
			hint="Activates trackbacks for an entry">
		<cfargument name="entryId" type="uuid" required="true" />
		<cfset getTrackbackGateway().activateTrackbacksByEntryId(arguments.entryId) />
	</cffunction>
	
	<cffunction name="deleteTrackbacksByEntryId" access="public" output="false" returntype="void" 
			hint="Deletes trackbacks for an entry">
		<cfargument name="entryId" type="uuid" required="true" />
		<cfset getTrackbackGateway().deleteTrackbacksByEntryId(arguments.entryId) />
	</cffunction>
	
	<cffunction name="toggleTrackbackDisplay" access="public" output="false" returntype="void" 
			hint="Toggles a trackback display (show or hide)">
		<cfargument name="trackbackId" type="uuid" required="true" />
		<cfargument name="action" type="string" required="true" />
		<cfset getTrackbackGateway().toggleTrackbackDisplay(arguments.trackbackId, arguments.action, getUserFacade().getUser().getUserId()) />
	</cffunction>
	
	<cffunction name="deleteTrackbacks" access="public" output="false" returntype="void" hint="Deletes trackbacks">
		<cfargument name="deleteIds" type="string" required="true" />
		<cfset getTrackbackGateway().deleteTrackbacks(arguments.deleteIds) />
	</cffunction>
	
	<!---
	PUBLIC FUNCTIONS - DAO RELATED
	--->
	<cffunction name="getTrackbackById" access="public" output="false" returntype="Trackback"
		hint="Retrieves a specific trackback">
		<cfargument name="trackbackId" type="string" required="true" />
		
		<cfset var trackback = getTrackbackBean().init(arguments.trackbackId) />

		<cfset getTrackbackDAO().read(trackback) />

		<cfreturn trackback />
	</cffunction>
	
	<cffunction name="createTrackback" access="public" output="false" returntype="void" hint="Creates a trackback">
		<cfargument name="trackback" type="Trackback" required="true" />
		<cfset getTrackbackDAO().create(arguments.trackback) />
	</cffunction>
	
	<cffunction name="updateTrackback" access="public" output="false" returntype="void" hint="Updates a trackback">
		<cfargument name="trackback" type="Trackback" required="true" />
		<cfset getTrackbackDAO().update(arguments.trackback) />
	</cffunction>
	
	<cffunction name="deleteTrackback" access="public" output="false" returntype="struct" hint="Deletes a trackback">
		<cfargument name="trackback" type="Trackback" required="true" />
		<cfset getTrackbackDAO().delete(arguments.trackback) />
	</cffunction>
</cfcomponent>